<!-- eslint-disable vue/multi-word-component-names -->
<template>
  <div>
    <input type="text"
           v-if="flag"
           v-ref="myInput"
           v-focus>
    <button @click="changeInput">搜索按钮</button>
    <input type="text" value="123" v-color=color1>
  </div>
</template>

<script>
export default {
  data(){
    return {
      color1:'red'
    }
  },
  methods: {
    changeInput(){
      this.flag=!this.flag
      this.$$nextTick(()=>{this.$refs.myInput.focus()})
    }
  },
  directives:{
    focus:{
      inserted(el){
        el.focus()
      }
    }
  }
}
</script>